<?php
// +----------------------------------------------------------------------
// | 知识星球[基于ThinkPHP5开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2019 abcblockchain.io
// +----------------------------------------------------------------------
// | 后台管理使用了HisiPHP
// +----------------------------------------------------------------------
// | Author: abcblockchain.io
// +----------------------------------------------------------------------
namespace app\api\home;

use app\common\controller\Api;
use think\Db;
use app\common\model\PhoneCode;
use app\common\model\Users as usersModel;
use app\common\model\AdminAnnex as AnnexModel;

class Apis extends Api
{
    public function sendMsg()
    {
        $postData = $this->requestData;
        if (!$postData['mobile'] || !$postData['type']) {
            $data['status'] = 0;
            $data['code'] = 1;
            $data['data'] = '参数不全';
            echo json_encode($data);
            exit();
        }
        if ($postData['type'] == 2 || $postData['type'] == 5) {
            $usersModel = new usersModel();
            $isHave = $usersModel->checkAccout($postData['mobile']);
            if (!$isHave) {
                $data['status'] = 0;
                $data['code'] = 2;
                $data['data'] = '账户不存在';
                echo json_encode($data);
                exit();
            }
        }
        $codeModel = new PhoneCode();
        $uid = $postData['uid'] ? $postData['uid'] : 0;
        $res = $codeModel->send($postData['mobile'], $uid, $postData['type']);
        if ($res) {
            $res = array(
                'status' => 1,
                'content' => '发送成功',
                'code' => 0,
            );
        } else {
            $res = array(
                'status' => 0,
                'content' => '服务繁忙',
                'code' => 1114,
            );
        }
        echo json_encode($res);
        exit();
    }

    /**
     * 获取最新版本号
     * @author
     */
    public function getVersion()
    {
        $postData = $this->requestData;
        if (isset($postData['type'])) {
            $map['type'] = $postData['type'];
            $map['status'] = 1;
            $versionInfo = Db::name('version')->where($map)->order('version desc')->find();
            $result = array(
                'status' => 1,
                'data' => $versionInfo ? $versionInfo : array(),
                'code' => 0,
            );
        } else {
            $result = array(
                'status' => 0,
                'data' => 'param error',
                'code' => 1,
            );
        }
        echo json_encode($result);
        exit;
    }

}